//
//  interitancePartTemplate.hpp
//  learnC++
//
//  Created by liuzhibing on 2018/6/21.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#ifndef inheritancePartTemplate_hpp
#define inheritancePartTemplate_hpp

#include <stdio.h>
#include <iostream>

template <class T,int size>
class StaticArrayBase {
protected:
    T m_array[size];
    
public:
    
    T &operator[](int index){
        return m_array[index];
    }
    
    T *getArray();
    
    void print()
    {
        for (int i = 0; i < size; i++)
            std::cout << m_array[i];
        std::cout << "\n";
    }
    
};

template <class T,int size>
class StaticArray3 : public StaticArrayBase<T, size> {
    
    
public:
    StaticArray3(){
        
    }
};

template <int size>
class StaticArray3<double, size> : public StaticArrayBase<double, size> {
    
    
public:
    void print()
    {
        for (int i = 0; i < size; i++){
            std::cout << std::scientific << StaticArrayBase<double, size>::m_array[i] << " ";
            std::cout << std::scientific << this->m_array[i];//继承自模板后，需用this或者范围符来使用模板基类的成员和方法
            // note: gcc requires the StaticArray_Base<double, size>:: prefix in the above line.  Still not sure why.
        }
        std::cout << "\n";
            
    }
};

#endif /* interitancePartTemplate_hpp */
